package com.ia2014.tp.portal2.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ia2014.tp.portal2.facades.FacadeVenta;
import com.ia2014.tp.portal2.vo.ArticuloVO;
/**
 * Realiza de los objetos de portal para 
 * @author DiegoAlejandro
 *
 */
@WebServlet("/portal")
public class PortalServlet extends AbstractServlet {
	private static final long serialVersionUID = 3763571440490518886L;
	
	@EJB
	private FacadeVenta facade;

	public PortalServlet(){
		super();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		this.comprobarSession(req, resp);
		this.process(req, resp);
	
	}

	private void process(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException{
		
		HttpSession session = req.getSession(false);
		List<ArticuloVO> articulos = this.facade.getListaArticulos();
		if (articulos == null){
			articulos = new ArrayList<ArticuloVO>();
		}
		
		session.setAttribute("articulosList", articulos);
		resp.sendRedirect("portal.jsp");
		
	}
}
